package com.leetcode.offer.chapter5;

import java.util.Arrays;

/**
 * @author Dennis Li
 * @date 2020/7/28 20:53
 */
public class IsStraight_61 {

    public boolean isStraight(int[] nums) {
        Arrays.sort(nums);
        int zero = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] == 0) zero++;
            else if (nums[i + 1] - nums[i] != 1) {
                while (zero > 0 && nums[i + 1] - nums[i] != 1) {
                    zero--;
                    nums[i]++;
                }
                if (nums[i + 1] - nums[i] != 1) return false;
            }
        }
        return true;
    }

}
